#####POOLED ANXIETY DATA####
#front matter
rm(list=ls())
#setwd('E:/psrsd/anxiety2016/data')
setwd('/Volumes/MONOGAN/psrsd/anxiety2016/data/REPLICATION/')

#load data
pooled<-read.csv('anxiety1216.csv',header=T)
#head(pooled);tail(pooled)

#Create GOP indicator
pooled$gop<-as.numeric(pooled$pid_x>.5)

#Create subsets
pooled.12<-subset(pooled,subset=year==2012)
pooled.16<-subset(pooled,subset=year==2016)

#Compare party differences by year
#pdf('../../measurementBox2012.pdf',width=4,height=4,pointsize=8)
boxplot(anxiety.own~gop,data=pooled.12,ylim=c(0,1),axes=F,ylab="Anxiety",xlab="2012 Data")
axis(1,at=c(1,2),labels=c("Democrats","Republicans"));axis(2);box()
#dev.off()

#pdf('../../measurementBox2016.pdf',width=4,height=4,pointsize=8)
boxplot(anxiety.own~gop,data=pooled.16,ylim=c(0,1),axes=F,ylab="Anxiety",xlab="2016 Data")
axis(1,at=c(1,2),labels=c("Democrats","Republicans"));axis(2);box()
#dev.off()

#T-tests
t.test(anxiety.own~year,data=pooled,alternative="less")
t.test(anxiety.own~year,data=pooled,subset=gop==0,alternative="less")
t.test(anxiety.own~year,data=pooled,subset=gop==1,alternative="less")

t.test(anxiety.own~gop,data=pooled)
t.test(anxiety.own~gop,data=pooled,subset=year==2012)
t.test(anxiety.own~gop,data=pooled,subset=year==2016)

#Separate indicators
t.test(ang.own~year,data=pooled,subset=gop==0)
t.test(ang.own~year,data=pooled,subset=gop==1)
t.test(afr.own~year,data=pooled,subset=gop==0)
t.test(afr.own~year,data=pooled,subset=gop==1)
t.test(hp.own~year,data=pooled,subset=gop==0)
t.test(hp.own~year,data=pooled,subset=gop==1)
t.test(prd.own~year,data=pooled,subset=gop==0)
t.test(prd.own~year,data=pooled,subset=gop==1)
